package com.qzimp.fujiancuo.controller;

import com.qzimp.fujiancuo.entity.vo.ResultVo;
import com.qzimp.fujiancuo.service.FileUpLoadService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@Api(tags = "文件上传")
@RequestMapping("/file")
public class FileUpLoadController {

    @Autowired
    private FileUpLoadService fileUpLoadService;

    /**
     * 文件上传
     *
     * @param file 文件
     * @return 访问链接
     */
    @PostMapping("/upLoad")
    @ApiOperation("文件上传")
    public ResultVo upLoad(@ApiParam("文件") @RequestBody(required = false) MultipartFile file) throws IOException {
        if (file == null)
            return new ResultVo(1, "请求成功", "请先选择文件！", true);
        String url = fileUpLoadService.upLoad(file);
        return new ResultVo(1, "请求成功", url, true);
    }


}
